package com.brspace.qualitycontrol.controller.admin;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.brspace.qualitycontrol.entity.Letter;
import com.brspace.qualitycontrol.entity.PeopleHotline;
import com.brspace.qualitycontrol.service.PeopleHotlineService;
import com.brspace.qualitycontrol.service.ProcessNodeService;
import com.brspace.qualitycontrol.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 百姓热线 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2021-05-06
 */
@Api(description = "百姓热线")
@RestController
@RequestMapping("/admin/people-hotline")
public class PeopleHotlineController {
    @Resource
    private PeopleHotlineService peopleHotlineService;
    @Resource
    private ProcessNodeService processNodeService;
    /**
     * 信息录入
     * @Author wangt
     * @Date 2021-05-06 14:04:29
     */
    @ApiOperation("信息录入")
    @PostMapping("add")
    public R add(@ApiParam("录入对线") @RequestBody PeopleHotline peopleHotline){
        if (peopleHotlineService.add(peopleHotline)>0) {
            return R.ok();
        }
        return R.error();
    }
    @ApiOperation("分页查询")
    @PostMapping("list/{page}/{limit}")
    public R pageList(
            @ApiParam(value = "当前页码",required = true) @PathVariable Long page,
            @ApiParam(value = "每页多少数据", required = true) @PathVariable Long limit){
        Page<PeopleHotline> pageParam = new Page<>(page, limit);
        IPage<PeopleHotline> pageModel = peopleHotlineService.selectPage(pageParam, null);
        List<PeopleHotline> records = pageModel.getRecords();
        long total = pageModel.getTotal();
        return R.ok().data("total",total).data("rows",records);
    }
    /**
     * 根据ID查询一个
     * @Author wangt
     * @Date 2021-05-06 14:38:17
     */
    @ApiOperation("根据ID查一个")
    @PostMapping("findById/{id}")
    public R findById(@ApiParam(value = "id",required = true) @PathVariable String id){
        return R.ok().data("list",peopleHotlineService.findById(id)).data("sort",processNodeService.findPeoPle(id));
    }
    @ApiOperation("审核")
    @PostMapping("examine/{userName}/{uid}")
    public R examine(
            @ApiParam(value = "下阶段办理人ID" ,required = true) @PathVariable String userName,
            @ApiParam(value = "当前节点办理人ID" , required = true) @PathVariable String uid,
            @ApiParam("对象类型") @RequestBody PeopleHotline peopleHotline){
        return peopleHotlineService.examine(peopleHotline,userName,uid);
    }

}

